Skip to content

Conversation

@Majoodeh
Copy link

@Majoodeh Majoodeh commented Feb 9, 2026

No description provided.

Copilot AI review requested due to automatic review settings February 9, 2026 14:09
@HackYourFutures HackYourFutures temporarily deployed to study-bridge-fe-user-lo-dtm7tr February 9, 2026 14:09 Inactive
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds client-side logout support by introducing a logout API call plus React Query mutation/hook wrappers, integrating session cleanup and navigation on logout.

Changes:

  • Added logoutApi() to call the server logout endpoint.
  • Added useLogoutMutation() to perform logout and clear client auth/query state.
  • Added a useLogout() hook wrapper to expose logout, isPending, and error.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
client/src/hooks/useLogout.ts Provides a small hook wrapper around the logout mutation for component use.
client/src/features/auth/mutations/useLogoutMutation.ts Implements the logout mutation and client-side cleanup (session/cache/nav).
client/src/api/auth/auth.api.ts Adds the /api/auth/logout API call used by the mutation.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 13 to 25
onSuccess: async () => {
clearSession();
localStorage.removeItem("hadSession");
qc.clear();
navigate("/", { replace: true });
},
onError: (error) => {
console.error("Logout failed:", error);
clearSession();
localStorage.removeItem("hadSession");
qc.clear();
navigate("/", { replace: true });
},
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

onSuccess and onError contain the same logout cleanup logic (clear session, remove localStorage flag, clear query cache, navigate). This duplication increases the risk of future drift; consider extracting a shared helper or using onSettled to run the common cleanup once, while keeping error logging separate if needed.

Copilot uses AI. Check for mistakes.
Comment on lines 14 to 24
clearSession();
localStorage.removeItem("hadSession");
qc.clear();
navigate("/", { replace: true });
},
onError: (error) => {
console.error("Logout failed:", error);
clearSession();
localStorage.removeItem("hadSession");
qc.clear();
navigate("/", { replace: true });
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The app already has a centralized “hard logout” flow via triggerLogout/AuthBootstrap (used by the Axios interceptors). Implementing separate cleanup/navigation logic here can lead to inconsistent behavior across logout paths. Consider reusing the centralized handler (and ensuring it also removes hadSession) so all logout entrypoints share one implementation.

Copilot uses AI. Check for mistakes.
Comment on lines 31 to 34
export async function logoutApi() {
const res = await apiProtected.post("/api/auth/logout");
return res.data;
}
Copy link

Copilot AI Feb 9, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

logoutApi returns res.data with an implicit any type, but callers don’t use the return value. To keep API helpers consistent with register*Api (which just awaits the request) and improve typing, consider returning Promise<void> (or a specific response type if it’s meaningful) and avoid returning untyped data.

Suggested change
export async function logoutApi() {
const res = await apiProtected.post("/api/auth/logout");
return res.data;
}
export async function logoutApi(): Promise<void> {
await apiProtected.post("/api/auth/logout");
}

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@Dmytro-Doronin Dmytro-Doronin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change everything that Copilot suggests you and call logOut api inside log out modal

@@ -0,0 +1,14 @@
import { useLogoutMutation } from "../features/auth/mutations/useLogoutMutation";

export const useLogout = () => {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You do not need this hook, you can use useLogoutMutation directly in header component

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants